package com.xuetang9.t9.hotel.services.impl;



import com.xuetang9.t9.hotel.beans.Reservation;
import com.xuetang9.t9.hotel.mapper.IReservationMapper;
import com.xuetang9.t9.hotel.mapper.condition.impl.ReservationCondition;
import com.xuetang9.t9.hotel.services.IReservationService;
import com.xuetang9.t9.hotel.utils.OverallConstant;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import com.xuetang9.t9.hotel.utils.SnowFlake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 预订的业务层
 * @author pang
 */
@Service
public class ReservationServiceImpl implements IReservationService {

    @Autowired
    private IReservationMapper reservationDao;

    @Autowired
    private SnowFlake snowFlake;

    @Override
    public boolean save(Reservation reservation) {
        if(null == reservation){
            return false;
        }
        reservation.setReservationId(snowFlake.nextId());
        return reservationDao.insert(reservation) > 0;
    }

    @Override
    public boolean remove(Long ReservationId) {
        return reservationDao.delete(ReservationId) > 0;
    }

    @Override
    public boolean alter(Reservation reservation) {
        return reservationDao.update(reservation) > 0;
    }

    @Override
    public PageBean findByAll(ReservationCondition reservationCondition) {
        if(reservationCondition == null){
            reservationCondition = new ReservationCondition();
        }
        PageBean pageBean = new PageBean();
        pageBean.ok(reservationDao.selectByAll(reservationCondition));
        pageBean.setCount(queryCount(reservationCondition));
        return pageBean;
    }

    @Override
    public Long queryCount(ReservationCondition reservationCondition) {
        return reservationDao.selectByCount(reservationCondition);
    }

    @Override
    public Integer queryCount(int pageSize) {
        return null;
    }

}
